package com.example.chang.law_doc.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.chang.law_doc.R;
import com.example.chang.law_doc.entity.LawItemData;

import java.util.List;

/**
 * Created by chang on 2018/3/9.
 * 项目描述：
 */

public class LawItemAdapter extends BaseAdapter {
    private Context mContext;
    private List<LawItemData>mList;

    private LayoutInflater inflater;
    private LawItemData data;

    public LawItemAdapter(Context mContext, List<LawItemData> mList){
        this.mContext = mContext;
        this.mList = mList;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        //第一次加载
        if (view == null) {
            viewHolder = new ViewHolder();
            view = inflater.inflate(R.layout.activity_law_item, null);
            viewHolder.tv_title = view.findViewById(R.id.tv_title);
            viewHolder.tv_content = view.findViewById(R.id.tv_ex_content);
            //设置缓存
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        data = mList.get(i);
        viewHolder.tv_title.setText(data.getTitle());
        viewHolder.tv_content.setText(data.getContent());
        return view;
    }
    class ViewHolder {
        private TextView tv_title;
        private TextView tv_content;


    }
}
